import request from './request'
import { useUserStore } from '../store/modules/user'
// 获取一级地址
export function getPrimaryAddress() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/address/',
    method: 'get',
    headers: token,
  })
}

// 获取子级地址
export function getSecondAddress(parentId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/address/' + parentId,
    method: 'get',
    headers: token,
  })
}

// 获取系统全局设置的地址库级别
export function getAddressLevel() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/set/getAddressLevel',
    method: 'get',
    headers: token,
  })
}

/**
 * 地址识别
 * @param {string} text - 被识别的文本
 */
export function addressRecognition(text: string) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/map/addressRecognition',
    method: 'post',
    headers: token,
    data: {
      text,
    },
  })
}
